home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS4.lha / helios_demo_disk4 / docs / userinterface / Stack.doc < prev    next >
Encoding:
Text File  |  1994-11-10  |  5.3 KB  |  121 lines

  1. *****************
  2. The Stack Display
  3. *****************
  4.  
  5. In HeliOS you have a continuous on-screen display of the stack in a strip 
  6. along the top of the Interpreter display window.
  7.  
  8. The top ten stack items are displayed, with the top-of-stack item shown in
  9. red, and the number of items on the stack shown in yellow.
  10.  
  11. This stack display is replaced by the DEBUG control panel when you enter
  12. "debug" mode.
  13.  
  14. The stack display always shows the current stack status, and is very useful
  15. for beginners who are unsure of how the stack works.
  16.  
  17. In fact, this feature of HeliOS is ENTIRELY for the benefit of beginners,
  18. because once you are experienced with stack manipulation you will rarely
  19. need a full graphical display such as this.
  20.  
  21. In fact, the rest of this text on the stack is aimed at the beginner......
  22.  
  23. The biggest single difficulty the beginner with a stack-oriented language
  24. faces seems always to lie in grasping how the stack works.  The first
  25. thing any commentator or reviewer always points out about Forth is the
  26. difficulty of using the stack and reverse Polish notation, and in general
  27. there is a negative "fear" of this topic in most beginner's minds before
  28. they even get started.
  29.  
  30. Perhaps you too have been assailed by doubts about these matters?
  31.  
  32. This initial confusion and "fear" can present quite unnecessary and even
  33. insurmountable problems in some cases, which is a great pity because the
  34. stack really is very easy to understand once you can see exactly what
  35. is happening.  It is actually utterly trivial and simple, so forget all
  36. jargon and complicated explanations you have read and learn by practise.
  37.  
  38. HeliOS is unashamedly dedicated to helping the beginner rather than
  39. presenting a highly "difficult" image to impress by sheer complication as
  40. many languages do.  Programming can be easy and pleasurable, and we hope
  41. you will appreciate how easy the stack can be by using the excellent
  42. stack display included just for your benefit!
  43.  
  44. Many texts on Forth, when trying to describe stack concepts and "reverse
  45. Polish notation", struggle to explain the stack with all manner of diagrams
  46. and analogies.  The fact is that without anything concrete to see, and
  47. only abstract highly technical explanations to help, often the poor student
  48. is left bemused.  Just looking at a string of confusing stack operators on
  49. the page of a book, accompanied by an often frightening and complicated 
  50. explanation is not at all helpful.
  51.  
  52. Many would-be Forth programmers give up at this stage, but in fact the use
  53. of a stack to pass parameters is very simple if you approach it with an
  54. open mind and a freedom from all the usual associated jargon.
  55.  
  56. Forget all the talk of "reverse Polish notation" which you might have read,
  57. and simply sit at your Amiga and experiment with the stack for yourself.
  58.  
  59. Just type in a few numbers and observe the stack display.  Use a few of
  60. the simple arithmetic operators such as "+" or "-" and watch what happens
  61. to the numbers on the stack.
  62.  
  63. Use a few of the simple stack operators like DUP and ROT and watch how
  64. they affect numbers on the stack.  Try to build up just a small repertoire
  65. of commands which you understand before trying to learn too many of the
  66. more complex operators.
  67.  
  68. Spend just a few hours "playing" wiuth the stack and once you are used to
  69. seeing a "concrete" display of what is happening, the use of the stack will
  70. become very clear.
  71.  
  72.  
  73. **************************
  74. HeliOS Stack Control Words
  75. **************************
  76.  
  77. There seem to be an awful lot of these, but they are very easy to use
  78. and learn, and are very, very important in the production of efficient
  79. and readable HeliOS code.
  80.  
  81. Use these words to MINIMISE THE NUMBER OF STACK MANIPULATION WORDS which
  82. you employ.
  83.  
  84. DO NOT write long strings of DUPs and SWAPs and ROTs, as this produces
  85. grotesquely unreadable code and is horrifyingly inefficient, since these
  86. words contribute exactly nothing to getting the logical task done, being
  87. merely an undesirable OVERHEAD of any Forth based system.
  88.  
  89. So....always use ONE word if possible instead of several.
  90.  
  91. N.B.
  92.  
  93. ALL the HeliOS stack management words are machine coded for speed, as
  94. distinct from most Forth systems, where words like ROLL, for example, if
  95. they are present at all, are often coded in slower high-level Forth.
  96.  
  97. This has rightly led to their use being generally condemned as grossly
  98. inefficient in terms of CPU time, but in HeliOS all the stack management
  99. words are machine coded and ultra  efficient, so use the words which give
  100. you simplest operation.
  101.  
  102. The "less stack control words used the better" is a good rule!
  103.  
  104. "Keep the stack small" is another good rule!
  105.  
  106. If your program stack gets very big you should probably be doing things
  107. another way, such as using named variables.  It is not "macho" or clever
  108. to "think" you can handle huge stacks with complicated stack control code.
  109. This sort of thing is merely going to land you in trouble with buggy code
  110. which is hard to read and change, so if you have more than three or four
  111. items on the stack, think carefully about why!
  112.  
  113. Good HeliOS programming starts (and often stops!) here, so really get to
  114. know as many stack control words as possible so that their use becomes
  115. second nature.
  116.  
  117. Set yourself up a dummy stack in Interactive mode and play with the stack
  118. control words you are not sure of until you see clearly how they work.
  119.  
  120. ***************************************************************************
  121.